﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.Globalization;

namespace University.Workshop.Business
{
    public static class EmployeeManager
    {
        public static void RegisterEmployeeManager(string ci,string name,string surname,string workArea,string email,string telephone,string address)
        {
            EmployeeRegister employee = new EmployeeRegister();
            employee.Dispose();
            if (string.IsNullOrEmpty(ci)||string.IsNullOrEmpty(name)||string.IsNullOrEmpty(surname)||string.IsNullOrEmpty(email)||string.IsNullOrEmpty(workArea)||string.IsNullOrEmpty(telephone)||string.IsNullOrEmpty(address))
            {
                throw new ArgumentException("All inputs are required.");
            }
            if (!Regex.IsMatch(email, @"^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})| ([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)$"))
            {
                throw new ArgumentException("the format the email is incorrect");
            }
            if (name.Length > 15 || name.Length < 5)
                throw new ArgumentException("Name: the maximum length is 15 and the minimum is 5");
            if (surname.Length > 15 || surname.Length < 5)
                throw new ArgumentException("Surname: the maximum length is 15 and the minimum is 5");
            if (address.Length > 25 || address.Length < 5)
                throw new ArgumentException("Address: the maximum length is 15 and the minimum is 5");
            if (ci.Length<5||ci.Length>8)
                throw new ArgumentException("the length Document of Identity max 8 and min 5");
           
            if (telephone.Length>10 || telephone.Length <5)   throw new ArgumentException("the length telephone max is 10 and min 5");
            if (employee.ExistEmployee(ci))   throw new ArgumentException("the employee exist");   
            try
            {
                Convert.ToInt32(ci,CultureInfo.InvariantCulture);
            }
            catch
            {

                throw new ArgumentException("the format ci is invalid ");
            }
            try
            {
                Convert.ToInt32(telephone,CultureInfo.InvariantCulture);
            }
            catch
            {
                throw new ArgumentException("the format telephone is invalid");
            }
            employee.RegisterEmployee(new Employee { CI = ci, NameEmployee = name, Surname = surname, Email = email, WorkArea = workArea, Telephone = telephone, Address = address });
        }
    }
}
